package dht.mains;

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;

import dht.data.DhtData;
import dht.data.Options;
import dht.node.Node;

public class ClientMassSpammingDHT {

	/**
	 * @param args
	 */

	public static void main(String[] args) throws InterruptedException {

		Node mySelf = null;

		int dim = Options.dimensions;
		boolean init = false;
		//String adrrIp = "192.168.1.77";
		//String adrrIp="192.168.1.26";
		String adrrIp=args[0];
		try {
			mySelf = new Node(dim,init,adrrIp); 
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		mySelf.start();
		
		while (mySelf.readyWork==false) {
			Thread.sleep(10);
		}
		
		System.out.println("coucou je suis arrivé la...");
		System.out.println("Starting to force The DHT :D");
		ArrayList<ArrayList<String>> dests=new ArrayList<ArrayList<String>>();
		for (int i=0;i<200;i++) {
			DhtData<Integer> d=new DhtData<Integer>(i);
			ArrayList<String> where=new ArrayList<String>();
			where.add(d.toString());where.add(d.toString());
			mySelf.async_PUT(where,d);
			dests.add(where);
		}
		int cpt=0;
		while (cpt<200) {
			cpt+=mySelf.finished_PUT().size();
			Thread.sleep(100);
		}
		int d=0;
		System.out.println("put done...");
		for (ArrayList<String> t : dests) {
			System.out.println("cela devrait être "+d+" que je reçois et je reçois : "+mySelf.GET(t));
			d++;
		}
		mySelf.QUIT();
		return;
	}

}


